package cn.yuxiaoyuan.controller;

import cn.yuxiaoyuan.result.JSONResult;
import cn.yuxiaoyuan.util.TxCosUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author solargen
 * @version 1.0
 * @date 2025/6/22 15:54
 */
@RestController
@RequestMapping("/cos")
public class COSController {
    @Autowired
    private TxCosUtil txCosUtil;
    @PostMapping("/upload")
    public JSONResult upload(@RequestParam("file") MultipartFile file,
                             @RequestParam("module")String module) {
        String name = System.currentTimeMillis() +"."+ module;
        String upload = txCosUtil.upload(file, name);
        return JSONResult.success(upload);
    }
}
